package com.xianguo.datacenter.mapping;

import java.util.List;

import org.apache.ibatis.annotations.Insert;
import org.apache.ibatis.annotations.Options;
import org.apache.ibatis.annotations.Param;
import org.apache.ibatis.annotations.Result;
import org.apache.ibatis.annotations.Results;
import org.apache.ibatis.annotations.Select;
import org.apache.ibatis.annotations.Update;

import com.xianguo.datacenter.domain.CommodityType;

/**
 * 分类数据源
 * @人员 鲜果 
 *
 */
public interface CommodityTypeMapper {
	
	@Select("select * from ims_zgcj_ewei_class where state = 0 and uid = #{uid}")
	public List<CommodityType> findCommTypeByid(@Param("uid")int uid);
	
	@Select("select * from ims_zgcj_ewei_class where id = #{id}")
	@Results(value={
			@Result(property="parmen",column="super" )
	})
	public CommodityType findCommTypeByidOne(@Param("id")int id);
	
	@Select("select * from ims_zgcj_ewei_class where level = 1 and state = 0 and uid = #{uid}")
	@Results(value={
			@Result(property="parmen",column="super" )
	})
	public List<CommodityType> selectone(@Param("uid")int uid);
	
	@Insert("insert into ims_zgcj_ewei_class(name,super,uid,level) values(#{type.name},#{type.parmen},#{type.uid},#{type.level})")
	@Options(useGeneratedKeys = true, keyProperty = "type.id")
	public void addCommType(@Param("type")CommodityType type);
	
	@Update("update ims_zgcj_ewei_class set state = 1 where id = #{id} or super = #{id} and uid = #{uid}")
	public void deleteCommType(@Param("id")int id,@Param("uid")int uid);
	
	@Select("select * from ims_zgcj_ewei_class where state = 0 and super = #{super} and uid = #{uid}")
	@Results(value={
			@Result(property="parmen",column="super" )
	})
	public List<CommodityType> findCommTypeBySuper(@Param("super")int parmen,@Param("uid")int uid);
	
	@Update("update ims_zgcj_ewei_class set name = #{name} where state = 0 and id = #{id} and uid = #{uid}")
	public void updateCommType(@Param("id")int id,@Param("uid")int uid,@Param("name")String name);
	
}
